/*
 * Algorithms.h
 *
 *  Created on: 22 Aug 2011
 *      Author: Allan
 */

#ifndef ALGORITHMS_H_
#define ALGORITHMS_H_

// C++ includes
#include <algorithm>
#include <set>
#include <vector>
using namespace std;

// Boost includes
#include <boost/foreach.hpp>

const unsigned 
IndexOf(const string& word, const vector<string>& words);

const bool 
IsContained(const string& word, const vector<string>& words);

const vector<string> 
Union(const vector<string>& words1, const vector<string>& words2);

const vector<string> 
Intersection(const vector<string>& words1, const vector<string>& words2);

const vector<string> 
Difference(const vector<string>& words1, const vector<string>& words2);

const vector<string> 
Unique(const vector<string>& words);

template<typename Predicate> const vector<string>
Filter(const vector<string>& words, Predicate predicate)
{
	vector<string> filtered_words;
	
	BOOST_FOREACH(const string& word, words) 
		if(predicate(word))
			filtered_words.push_back(word);
			
	return filtered_words;
}

template<typename Predicate> const vector<string>
Remove(const vector<string>& words, Predicate predicate)
{
	vector<string> filtered_words;
	
	BOOST_FOREACH(const string& word, words) 
		if(!predicate(word))
			filtered_words.push_back(word);
			
	return filtered_words;
}

#endif /* ALGORITHMS_H_ */
